<?php
if( isset( $_POST[ 'Upload' ] ) ) {
    $target  = "uploads/";
    //$target = $target . md5(uniqid(microtime(true),true)) . "/";
    $target .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
    //识别文件类型
    $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ];
    $uploaded_type = $_FILES[ 'uploaded' ][ 'type' ];
    $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ];
    if( ( $uploaded_type == "image/jpeg" || $uploaded_type == "image/png" ) &&
        ( $uploaded_size < 100000 ) ) {
        if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target ) ) {
            echo "<pre>图片上传失败</pre>";
        }
        else {
            echo "upload succ <br> ";
            echo "<img src='$target'>";
        }
    }
    else {
        echo "<pre>only png and jpeg allowed ,or too big</pre>";
    }
}else{
    include "form.html";
    show_source(__FILE__);
}
?>